﻿using SupportLayer.Objetos.Cliente;
using SupportLayer.Objetos.Outros;
using SupportLayer.Objetos.Produto;
using SupportLayer.Objetos.Usuario;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataLayer
{
  public class ContextoBD : DbContext
  {
    #region DbSet Clientes
    public DbSet<ClienteClass> Clientes { get; set; }
    #endregion
    #region DbSet Outros
    public DbSet<BannerClass> Banners { get; set; }
    public DbSet<ContatoClass> Contatos { get; set; }
    #endregion
    #region DbSet Produtos
    public DbSet<AvaliacaoClass> Avaliacoes { get; set; }
    public DbSet<CategoriaClass> Categorias { get; set; }
    public DbSet<CategoriaMasterClass> CategoriasMaster { get; set; }
    public DbSet<CategoriaSecundariaClass> CategoriasSecundarias { get; set; }
    public DbSet<DestaqueClass> Destaques { get; set; }
    public DbSet<DimensoesClass> Dimensoes { get; set; }
    public DbSet<DividirClass> Dividir { get; set; }
    public DbSet<EspecificacaoClass> Especificacoes { get; set; }
    public DbSet<FotosClass> Fotos { get; set; }
    public DbSet<MarcaClass> Marcas { get; set; }
    public DbSet<ProdutoClass> Produtos { get; set; }
    public DbSet<PromocaoClass> Promocoes { get; set; }
    public DbSet<ViewsClass> Views { get; set; }
    #endregion
    #region DbSet Usuário
    public DbSet<UsuarioClass> Usuarios { get; set; }
    #endregion

    public ContextoBD()
      : base(@"Data Source=SANDER-PC;Initial Catalog=ByBike;Integrated Security=True")
      //: base(@"Data Source=67.228.156.127;Initial Catalog=ByBike;Persist Security Info=True;User ID=bybike;Password=Galodoido13")
    {
      Database.SetInitializer<ContextoBD>(null);
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
      try
      {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

        #region Clientes
        modelBuilder.Entity<ClienteClass>().HasKey(c => new { c.ID });
        #endregion
        #region Outros
        modelBuilder.Entity<BannerClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<ContatoClass>().HasKey(c => new { c.ID });
        #endregion
        #region Produto
        modelBuilder.Entity<AvaliacaoClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<CategoriaClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<CategoriaMasterClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<CategoriaSecundariaClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<DestaqueClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<DimensoesClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<DividirClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<EspecificacaoClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<FotosClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<MarcaClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<ProdutoClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<PromocaoClass>().HasKey(c => new { c.ID });
        modelBuilder.Entity<ViewsClass>().HasKey(c => new { c.ID });
        #endregion
        #region Usuário
        modelBuilder
            .Entity<UsuarioClass>()
            .HasKey(c => new { c.ID });
        #endregion

      }
      catch (Exception)
      {
        throw;
      }
    }

  }
}
